# == Schema Information
#
# Table name: attachments
#
#  id                :integer          not null, primary key
#  file              :string
#  user_id           :integer
#  file_size         :integer
#  filename          :string(255)
#  original_filename :string(255)
#  content_type      :string(255)
#  type              :string(255)
#  created_at        :datetime         not null
#  updated_at        :datetime         not null
#  width             :integer
#  height            :integer
#


class Attachment < ActiveRecord::Base

  belongs_to :user

  before_save :set_file_property

  def self.inherited base
    super
    mount_uploader :file, "#{base.name}Uploader".constantize
  end

  def set_file_property
    fileUploader = self.file
    self.content_type = fileUploader.content_type
    self.filename = fileUploader.filename
    self.file_size = fileUploader.size
    self.original_filename = fileUploader.file.original_filename
  end

end

